home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / kernel / makefstm.0 / MakeFastMem.asm next >
Assembly Source File  |  1990-01-14  |  14KB  |  477 lines

  1.                 OPT L-,C+,D-,O+         ; Devpac Amiga stuff, skip this
  2.                                         ; for other assemblers
  3.  
  4. *  MakeFastMem v1.0    891028      E. Lundevall
  5. *
  6. *  A little program to provide folks with only chipmem some "fastmem"
  7. *  for programs that require fastmem (what's the point with that?!?).
  8. *
  9.  
  10.                 INCDIR  Assembler:include/
  11. ;                INCLUDE mymacros.i  ; You don't have this one
  12.                 INCLUDE exec/exec_lib.i           ; Library offsets in
  13.         INCLUDE    intuition/intuition_lib.i ; those four files
  14.                 INCLUDE libraries/dos_lib.i 
  15.         INCLUDE workbench/icon_lib.i
  16.                 INCLUDE exec/execbase.i
  17.         INCLUDE exec/alerts.i
  18.         INCLUDE exec/tasks.i
  19.                 INCLUDE exec/memory.i
  20.         INCLUDE    intuition/intuition.i
  21.         INCLUDE libraries/dosextens.i
  22.         INCLUDE workbench/startup.i
  23.         INCLUDE workbench/workbench.i
  24.  
  25.  
  26. ; Necessary macros from "mymacros.i"
  27.  
  28.  
  29. jsrb            MACRO
  30.                 jsr     _LVO\1(a6)
  31.                 XREF.L  _LVO\1
  32.                 ENDM
  33.  
  34.  
  35. push            MACRO
  36.                 movem.\0 \1,-(sp)
  37.                 ENDM
  38.  
  39. pop             MACRO
  40.                 movem.\0 (sp)+,\1
  41.                 ENDM
  42.  
  43. openlib         MACRO
  44.                 lea     \1,a1
  45.                 move.l  \2,d0
  46.                 jsrb    OpenLibrary
  47.                 ENDM
  48.  
  49.  
  50. ; Some symbol definitions
  51.  
  52. VERSION        EQU    33    ; Use only v1.2 och higher
  53. REQHEIGHT    EQU    80    ; Height of the error requester
  54. REQWIDTH    EQU    300    ; Width of the error requester
  55.  
  56.  
  57. MakeFastMem     movea.l 4,a6
  58.         push.l  d0/a0    ; Save d0 & a0 in case we are run from the CLI
  59.         suba.l    a1,a1    
  60.         jsrb    FindTask ; Find the address to our own process
  61.         movea.l    d0,a4
  62.         pop.l    d0/a0
  63.         tst.l    pr_CLI(a4) ; Check if we are running from the CLI
  64.         beq    fromWB
  65.  
  66.  
  67. ********************** Code for CLI part *********************************
  68.  
  69. fromCLI        subq.l  #1,d0    ; Decrement argument length to strip LF
  70.                 beq     usage    ; No argument given, tell user how to use us
  71.                 move.b  #0,0(a0,d0.l) ; Make argument string NULL-terminated
  72.                 bsr     asctodec ; Convert string to binary value
  73.                 bmi     usage    ; Not a positive number, display usage
  74.                 bsr    CreateFast ; Do the real work
  75.         tst.l    d0    
  76.         bne    .nosuccess ; Yack, something went wrong...
  77.  
  78.                 lea     okmess(pc),a0   ; We did it! Bring the news to
  79.                 moveq   #okmesslen,d0   ; the world!
  80.                 bra     WriteMess
  81.  
  82. .nosuccess      lea     errmess(pc),a0  ; Hey, who stole the memory...;-)
  83.                 moveq   #errmesslen,d0
  84.                 bsr     WriteMess
  85.         tst.l    d0        ; Did we succeed in writing message?
  86.         bne.s    .nodos
  87.         moveq    #10,d0
  88. .nodos        rts
  89.  
  90.  
  91. usage           lea     usemess(pc),a0      ; Write the usage message
  92.                 moveq   #usemesslen,d0
  93.                 bra     WriteMess
  94.  
  95.  
  96.  
  97. ********************** Code for Workbench part *****************************
  98.  
  99. fromWB        lea    pr_MsgPort(a4),a0    ; Wait for WB startup message
  100.         jsrb    WaitPort
  101.         lea    pr_MsgPort(a4),a0    ; Get the message...
  102.         jsrb    GetMsg
  103.         push.l    d0            ; ...and save it for later use
  104.  
  105.         movea.l    d0,a0
  106.         movea.l    sm_ArgList(a0),a1    ; Get the first argument:
  107.         move.l    wa_Name(a1),-(sp)    ; Name of program
  108.         move.l    wa_Lock(a1),-(sp)    ; Lock to directory of program
  109.  
  110.         openlib    dosname,#VERSION    ; Open dos.library
  111.         tst.l    d0
  112.         beq    nodos            ; Hey, where's DOS??!?
  113.  
  114.         movea.l    d0,a6            ; Change current directory to
  115.         pop.l    d1            ; the directory of our program
  116.         jsrb    CurrentDir
  117.  
  118.         movea.l    a6,a1            ; Close dos.library
  119.         movea.l    4,a6
  120.         jsrb    CloseLibrary
  121.     
  122. OpenIconLib    openlib    iconname,#VERSION    ; Open icon.library
  123.         tst.l    d0
  124.         beq    noiconlib
  125.  
  126.         movea.l    d0,a6            ; Get the icon for our program
  127.         pop.l    a0
  128.         jsrb    GetDiskObject
  129.         tst.l    d0
  130.         beq    noobj
  131.  
  132.         move.l    d0,d7            ; Put away address to DiskObject
  133.         movea.l    d0,a0
  134.         movea.l    do_ToolTypes(a0),a0
  135.         lea    tooltype(pc),a1        ; Search for ToolType 'FASTMEM'
  136.         jsrb    FindToolType
  137.         tst.l    d0
  138.         beq    notooltype
  139.  
  140.         movea.l    d0,a0
  141.         movea.l    a0,a1        ; Calculate the length of the string
  142.         moveq    #-1,d0
  143. .strlen        addq.l    #1,d0
  144.         tst.b    0(a1,d0.l)
  145.         bne.s    .strlen
  146.         bsr    asctodec     ; Convert ASCII string to binary value
  147.         bmi    nomemsize
  148.  
  149.         push.l    d0        ; Save memory size
  150.         bsr    FreeDO            ; Release the DiskObject
  151.         bsr    CloseIconLib    ; Ok, now close icon.libary
  152.         pop.l    d0
  153.         bsr    CreateFast    ; Do the real work
  154.         tst.l    d0
  155.         beq    exitWB        ; Yeah, we did it!
  156.         
  157.  
  158. *        
  159. * Some error conditions, show an error requester
  160. *
  161.  
  162. nocreatefast    lea    wberrmess(pc),a0
  163.         bsr    ShowRequest
  164.         bra    goodbye
  165.  
  166. noiconlib    lea    noiconlibmess(pc),a0    ; No icon.library available
  167.         bsr    ShowRequest
  168.         bra    goodbye
  169.  
  170. nodos        ALERT    (AG_OpenLib!AO_DOSLib)    ; Hey, no dos.libary!!
  171.         bra    goodbye            ; This is NOT good...
  172.  
  173. noobj        bsr    CloseIconLib        ; No icon for our program
  174.         lea    noobjmess(pc),a0
  175.         bsr    ShowRequest
  176.         bra    goodbye
  177.  
  178. notooltype    bsr    FreeDO            ; No FASTMEM tooltype
  179.         bsr    CloseIconLib
  180.         lea    notooltypemess(pc),a0
  181.         bsr    ShowRequest
  182.         bra    goodbye
  183.  
  184. nomemsize    bsr    FreeDO            ; Release icon
  185.         bsr    CloseIconLib        ; Incorrect value for the
  186.         lea    nomemsizemess(pc),a0    ; FASTMEM tooltype
  187.         bsr    ShowRequest
  188.  
  189. goodbye        moveq    #100,d0
  190.         bra    exitWB
  191.  
  192. **** Close icon.library *****
  193.  
  194. CloseIconLib    movea.l    a6,a1        
  195.         movea.l    4,a6
  196.         jsrb    CloseLibrary
  197.         rts
  198.  
  199.  
  200. **** Exit from Workbench *****
  201.  
  202. exitWB        jsrb    Forbid        ; Disable multitasking so that WB
  203.         pop.l    a1        ; won't unload us before we're ready
  204.         jsrb    ReplyMsg    ; Get the original WB startup message
  205.         rts            ; and reply to it, then exit
  206.         
  207.  
  208.  
  209.  
  210. *****************************************************************************
  211. * FreeDO - Do a FreeDiskObject
  212. *    Input:  d7 - address to DiskObject
  213. *        a6 - address to IconBase
  214. *    Result: None
  215. *****************************************************************************
  216.  
  217. FreeDO        movea.l    d7,a0            ; Release the allocated
  218.         jsrb    FreeDiskObject        ; resources for the icon
  219.         rts
  220.  
  221.  
  222.  
  223. ***************************************************************************
  224. * ShowRequest - display a requester with an error message
  225. *    Input:  a0 - address to an IntuiText
  226. *        a6 - address to ExecBase
  227. *    Result: None
  228. ***************************************************************************
  229.  
  230. ShowRequest    push.l    d2/d3/a2/a3
  231.         push.l    a0        
  232.         openlib    intuiname(pc),#VERSION
  233.         pop.l    a0
  234.         tst.l    d0
  235.         beq    .nointui
  236.  
  237.         movea.l    d0,a6
  238.         movea.l    a0,a1
  239.         suba.l    a0,a0
  240.         lea    darnmess(pc),a2
  241.         movea.l    a2,a3
  242.         moveq    #0,d0
  243.         moveq    #0,d1
  244.         move.l    #REQHEIGHT,d3
  245.         move.l    #REQWIDTH,d2
  246.         jsrb    AutoRequest
  247.         push.l    d0
  248.         movea.l    a6,a1
  249.         movea.l    4,a6
  250.         jsrb    CloseLibrary
  251.         pop.l    d0
  252. .nointui    pop.l    d2/d3/a2/a3
  253.         rts
  254.  
  255.  
  256.  
  257.  
  258. ****************************************************************************
  259. * CreateFast - Allocate a chunk of CHIPRAM and convert it to FASTRAM
  260. *    Input:    d0 - Size of the wanted FASTRAM chunk.
  261. *        a6 - pointer to ExecBase
  262. *    Result: d0 - NULL if successfull
  263. ****************************************************************************
  264.  
  265. CreateFast      push.l    d2-d3
  266.         addq.l    #8,d0    ; Adjust size for the mem chunk header
  267.         move.l  d0,d3   ; Allocate the "fast" memory
  268.                 move.l  #MEMF_CHIP+MEMF_PUBLIC+MEMF_CLEAR,d1
  269.                 jsrb    AllocMem
  270.                 move.l  d0,d2
  271.                 beq     .error1
  272.  
  273.                 move.l  #MH_SIZE,d0     ; Allocate space for a MemHeader
  274.                 move.l  #MEMF_CLEAR+MEMF_PUBLIC,d1
  275.                 jsrb    AllocMem
  276.                 tst.l   d0
  277.                 beq     .error2
  278.  
  279.                 lea     MakeFastMem(pc),a0  ; Disconnect the DATA hunk
  280.                 moveq   #0,d1               ; This is for the name field
  281.                 move.l  d1,-4(a0)           ; of the MemHeader.
  282.  
  283.                 move.l  d0,a1
  284.                 move.l  d2,MH_FIRST(a1) ; Use the first 8 bytes in the "fast"
  285.                 movea.l d2,a0           ; memory for a MemChunk
  286.                 addq.l  #8,d2
  287.                 move.l  d2,MH_LOWER(a1) ; Init the MemHeader as fastmem
  288.                 move.w  #MEMF_FAST+MEMF_PUBLIC,MH_ATTRIBUTES(a1)
  289.                                         ; We have made one big chunk
  290.                 subq.l  #8,d3           ; Subtract the MemChunk size and
  291.                 move.l  d3,MC_BYTES(a0) ; store the actual free size
  292.                 move.l  d3,MH_FREE(a1)
  293.                 add.l   d2,d3           ; Add size and lower address to get
  294.                 move.l  d3,MH_UPPER(a1) ; the upper bound
  295.                 moveq   #NT_MEMORY,d0   ; Store the node type
  296.                 move.b  d0,LN_TYPE(a1)
  297.                 lea     name,a0
  298.                 move.l  a0,LN_NAME(a1)  ; Store the address to the name
  299.  
  300.                 push.l  a1
  301.                 jsrb    Disable         ; Want to mess around by myself
  302.                 pop.l   a1
  303.                 lea     MemList(a6),a0  ; Add our memory node to the
  304.                 ADDHEAD                 ; MemList in ExecBase
  305.                 jsrb    Enable          ; Ok, let the others play
  306.  
  307.         moveq    #0,d0        ; We were successful, return 0 to
  308.         bra.s    .fastfixed    ; to say it's ok.
  309.  
  310. .error2         movea.l d0,a1           ; Trouble allocating memory, free
  311.                 move.l  d3,d0           ; the stuff we already have
  312.                 swap    d0              ; allocated
  313.                 jsrb    FreeMem
  314.  
  315. .error1      moveq    #-1,d0        ; Error, return -1 to say it's not ok.
  316. .fastfixed    pop.l    d2-d3
  317.         rts
  318.  
  319.  
  320.  
  321. *****************************************************************************
  322. * WriteMess - Write a message to the CLI Window.
  323. *             Input:    a0 - pointer to message
  324. *                       d0 - length of message
  325. *            a6 - pointer to ExecBase
  326. *             Result:    d0 - NULL if successful
  327. *****************************************************************************
  328.  
  329. WriteMess       push.l    d2-d3
  330.         move.l    d0,d3
  331.         push.l    a0
  332.                 lea     dosname(pc),a1
  333.                 jsrb    OldOpenLibrary  ; Open dos.library, any version
  334.                 tst.l   d0
  335.                 beq.s   .nomess
  336.  
  337.                 movea.l d0,a6
  338.                 jsrb    Output          ; Write the appropriate message
  339.                 move.l  d0,d1           ; in the CLI-window we were run
  340.                 pop.l    d2            ; from.
  341.                 jsrb    Write
  342.         pop.l    d2-d3
  343.         movea.l    a6,a1
  344.         movea.l    4,a6
  345.         jsrb    CloseLibrary    ; Close dos.library
  346.         moveq    #0,d0
  347. .exitwrite       rts
  348.  
  349.  
  350. .nomess        ALERT    (AG_OpenLib!AO_DOSLib)    ; No dos.library available!!!
  351.         moveq    #100,d0            ; This is REAL bad...
  352.         bra    .exitwrite        
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. *****************************************************************************
  360. * asctodec - Convert an ASCII string (NULL-terminated) to a binary value
  361. *    Input:    a0 - pointer to ASCII string
  362. *        d0 - length of string
  363. *    Result: d0 - Binary value
  364. *****************************************************************************
  365.  
  366. asctodec        push.l    d2
  367.         move.l  d0,d2
  368.                 subq.l  #1,d2               ; We will use nr of characters as an
  369.                 lsl.l   #2,d2               ; offset
  370.                 moveq   #0,d1
  371.                 move.l  d1,d0
  372.                 lea     .Numbers(pc),a1     ; Get base address of offset table
  373. .loop1          move.b  (a0)+,d1
  374.                 beq     .finished
  375.                 subi.b  #$31,d1
  376.                 bmi     .zero
  377.                 cmpi.b  #NumBase-1,d1
  378.                 bcs     .loop2
  379.                 moveq   #-1,d0
  380.                 bra     .finished
  381. .loop2          add.l   0(a1,d2.w),d0       ; Add value in table d1 times to d0.
  382.                 dbra    d1,.loop2
  383.                 moveq   #0,d1
  384. .zero           subq.w  #4,d2
  385.                 bra     .loop1
  386. .finished       pop.l    d2
  387.         rts
  388.  
  389. NumBase         EQU     10
  390. .Numbers        dc.l    1,10,100,1000,10000,100000,1000000,10000000,100000000
  391.  
  392.  
  393.  
  394.  
  395.  
  396. ****************** Some text & messages definitions ************************
  397.  
  398. dosname         dc.b    'dos.library',0
  399. iconname    dc.b    'icon.library',0
  400.         CNOP    0,2
  401. intuiname    dc.b    'intuition.library',0
  402.         CNOP    0,2
  403. tooltype    dc.b    'FASTMEM',0
  404.         CNOP    0,2
  405. errmess         dc.b    'P-p-p-pleeeaase... I need more memory!',10,0
  406. errmesslen      EQU     *-errmess
  407.                 CNOP    0,2
  408. okmess          dc.b    'FastMem created!',10,0
  409. okmesslen       EQU     *-okmess
  410.                 CNOP    0,2
  411. usemess         dc.b    'Usage: MakeFastMem  fastmemsize',10,0
  412. usemesslen      EQU     *-usemess
  413.         CNOP    0,2
  414. darntext    dc.b    'Darn!',0
  415.         CNOP    0,2
  416. noobjtext    dc.b    'No icon available',0
  417.         CNOP    0,2
  418. noiconlibtext    dc.b    'No icon.library',0,0
  419.         CNOP    0,2
  420. notooltypetext    dc.b    'No FASTMEM ToolType',0    
  421.         CNOP    0,2
  422. nomemsizetext    dc.b    'Error in FASTMEM value',0        
  423.         CNOP    0,2
  424. wberrtext    dc.b    'Not Enough ChipRAM',0
  425.         CNOP    0,2
  426.  
  427. *********** IntuiText structures for the error requester messages **********
  428.  
  429. noiconlibmess   dc.b    0,1       
  430.                 dc.b    RP_JAM1,0 
  431.                 dc.w    75,20       
  432.                 dc.l    0         
  433.                 dc.l    noiconlibtext
  434.                 dc.l    0          
  435.  
  436. notooltypemess  dc.b    0,1       
  437.                 dc.b    RP_JAM1,0 
  438.                 dc.w    60,20       
  439.                 dc.l    0         
  440.                 dc.l    notooltypetext
  441.                 dc.l    0          
  442.  
  443. nomemsizemess   dc.b    0,1       
  444.                 dc.b    RP_JAM1,0 
  445.                 dc.w    52,20       
  446.                 dc.l    0         
  447.                 dc.l    nomemsizetext
  448.                 dc.l    0          
  449.  
  450. noobjmess       dc.b    0,1       
  451.                 dc.b    RP_JAM1,0 
  452.                 dc.w    60,20       
  453.                 dc.l    0         
  454.                 dc.l    noobjtext
  455.                 dc.l    0          
  456.  
  457. wberrmess       dc.b    0,1       
  458.                 dc.b    RP_JAM1,0 
  459.                 dc.w    68,20       
  460.                 dc.l    0         
  461.                 dc.l    wberrtext
  462.                 dc.l    0          
  463.  
  464. darnmess        dc.b    0,1             ; it_FrontPen, it_BackPen
  465.                 dc.b    RP_JAM1,0       ; it_DrawMode, it_KludgeFill00
  466.                 dc.w    6,3             ; it_LeftEdge, it_TopEdge
  467.                 dc.l    0               ; it_ITextFont
  468.                 dc.l    darntext        ; it_IText
  469.                 dc.l    0               ; it_NextText
  470.  
  471.  
  472.  
  473.                 SECTION foo,DATA
  474. name            dc.b    'expansion ram',0
  475.                 END
  476.  
  477.